package com.h4313.ghome.ui.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class AnimatingFrameLayout extends FrameLayout {

	public AnimatingFrameLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public AnimatingFrameLayout(Context context) {
		super(context);
	}

	public AnimatingFrameLayout(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}

	public float getYFraction() {
        final int topmargin = ((LinearLayout.LayoutParams)getLayoutParams()).topMargin;
		return getY() + topmargin / getHeight();
    }

    public void setYFraction(float yFraction) {
    	final int topmargin = ((LinearLayout.LayoutParams)getLayoutParams()).topMargin;
    	
        final int height = getHeight() + ((LinearLayout.LayoutParams)getLayoutParams()).topMargin;
        setY(topmargin + ((height > 0) ? (yFraction * height) : -9999));
    }
	
}
